window['PP.mobile.ping.time'] && window['PP.mobile.ping.time'].push(new Date());

function $addToken(url, type, skey) {
	var token = $getToken(skey);
	if (url == "" || (url.indexOf("://") < 0 ? location.href : url).indexOf("http") != 0) {
		return url;
	}
	if (url.indexOf("#") != -1) {
		var f1 = url.match(/\?.+\#/);
		if (f1) {
			var t = f1[0].split("#"),
				newPara = [t[0], "&g_tk=", token, "&g_ty=", type, "#", t[1]].join("");
			return url.replace(f1[0], newPara);
		} else {
			var t = url.split("#");
			return [t[0], "?g_tk=", token, "&g_ty=", type, "#", t[1]].join("");
		}
	}
	return token == "" ? (url + (url.indexOf("?") != -1 ? "&" : "?") + "g_ty=" + type) : (url + (url.indexOf("?") != -1 ? "&" : "?") + "g_tk=" + token + "&g_ty=" + type);
};

function $getCookie(name) {
	var reg = new RegExp("(^| )" + name + "(?:=([^;]*))?(;|$)"),
		val = document.cookie.match(reg);
	return val ? (val[2] ? unescape(val[2]) : "") : null;
};

function $getToken(skey) {
	var skey = skey ? skey : $getCookie("skey");
	return skey ? $time33(skey) : "";
};

function $getUin() {
	var uin = $getCookie("uin") || $getCookie('uin_cookie') || $getCookie('pt2gguin') || $getCookie('o_cookie') || $getCookie('luin') || $getCookie('buy_uin');
	return uin ? parseInt(uin.replace("o", ""), 10) : "";
};

function $loadScript(obj) {
	if (!$loadScript.counter) {
		$loadScript.counter = 1;
	}
	var isObj = typeof(obj) == "object",
		url = isObj ? obj.url : arguments[0],
		id = isObj ? obj.id : arguments[1],
		obj = isObj ? obj : arguments[2],
		_head = document.head || document.getElementsByTagName("head")[0] || document.documentElement,
		_script = document.createElement("script"),
		D = new Date(),
		_time = D.getTime(),
		_isCleared = false,
		_timer = null,
		o = obj || {},
		data = o.data || '',
		charset = o.charset || "gb2312",
		isToken = o.isToken,
		skey = o.skey,
		timeout = o.timeout,
		isAutoReport = o.isAutoReport || false,
		reportOptions = o.reportOptions || {},
		reportType = o.reportType || 'current',
		reportRetCodeName = o.reportRetCodeName,
		reportSuccessCode = typeof(o.reportSuccessCode) == "undefined" ? 200 : o.reportSuccessCode,
		reportErrorCode = typeof(o.reportErrorCode) == "undefined" ? 500 : o.reportErrorCode,
		reportTimeoutCode = typeof(o.reportTimeoutCode) == "undefined" ? 600 : o.reportTimeoutCode,
		onload = o.onload,
		onsucc = o.onsucc,
		callbackName = o.callbackName || '',
		callback = o.callback,
		errorback = o.errorback,
		_jsonpLoadState = 'uninitialized';
	var complete = function(errCode) {
			if (!_script || _isCleared) {
				return;
			}
			_isCleared = true;
			if (_timer) {
				clearTimeout(_timer);
				_timer = null;
			}
			_script.onload = _script.onreadystatechange = _script.onerror = null;
			if (_head && _script.parentNode) {
				_head.removeChild(_script);
			}
			_script = null;
			if (callbackName) {
				if (callbackName.indexOf('.') == -1) {
					window[callbackName] = null;
					try {
						delete window[callbackName];
					} catch (e) {}
				} else {
					var arrJ = callbackName.split("."),
						p = {};
					for (var j = 0, jLen = arrJ.length; j < jLen; j++) {
						var n = arrJ[j];
						if (j == 0) {
							p = window[n];
						} else {
							if (j == jLen - 1) {
								try {
									delete p[n];
								} catch (e) {}
							} else {
								p = p[n];
							}
						}
					}
				}
			}
			if (_jsonpLoadState != "loaded" && typeof errorback == "function") {
				errorback(errCode);
			}
			if (isAutoReport && reportType != 'cross') {
				_retCoder.report(_jsonpLoadState == "loaded", errCode);
			}
		};
	var jsontostr = function(d) {
			var a = [];
			for (var k in d) {
				a.push(k + '=' + d[k]);
			}
			return a.join('&');
		};
	if (isAutoReport && reportOptions) {
		if (reportType == 'cross') {
			$returnCode(reportOptions).reg();
		} else {
			reportOptions.url = reportOptions.url || url.substr(0, url.indexOf('?') == -1 ? url.length : url.indexOf('?'));
			var _retCoder = $returnCode(reportOptions);
		}
	}
	if (data) {
		url += (url.indexOf("?") != -1 ? "&" : "?") + (typeof data == 'string' ? data : jsontostr(data));
	}
	if (callbackName && typeof callback == "function") {
		var oldName = callbackName;
		if (callbackName.indexOf('.') == -1) {
			callbackName = window[callbackName] ? callbackName + $loadScript.counter++ : callbackName;
			window[callbackName] = function(jsonData) {
				_jsonpLoadState = 'loaded';
				if (isAutoReport && reportRetCodeName) {
					reportSuccessCode = jsonData[reportRetCodeName];
				}
				callback.apply(null, arguments);
				onsucc && (onsucc());
			};
		} else {
			var arrJ = callbackName.split("."),
				p = {},
				arrF = [];
			for (var j = 0, jLen = arrJ.length; j < jLen; j++) {
				var n = arrJ[j];
				if (j == 0) {
					p = window[n];
				} else {
					if (j == jLen - 1) {
						p[n] ? (n = n + $loadScript.counter++) : '';
						p[n] = function(jsonData) {
							_jsonpLoadState = 'loaded';
							if (isAutoReport && reportRetCodeName) {
								reportSuccessCode = jsonData[reportRetCodeName];
							}
							callback.apply(null, arguments);
							onsucc && (onsucc());
						};
					} else {
						p = p[n];
					}
				}
				arrF.push(n);
			}
			callbackName = arrF.join('.');
		}
		url = url.replace('=' + oldName, '=' + callbackName);
	}
	_jsonpLoadState = 'loading';
	id = id ? (id + _time) : _time;
	url = (isToken !== false ? $addToken(url, "ls", skey) : url);
	_script.charset = charset;
	_script.id = id;
	_script.onload = _script.onreadystatechange = function() {
		var uA = navigator.userAgent.toLowerCase();
		if (!(!(uA.indexOf("opera") != -1) && uA.indexOf("msie") != -1) || /loaded|complete/i.test(this.readyState)) {
			if (typeof onload == "function") {
				onload();
			}
			complete(_jsonpLoadState == "loaded" ? reportSuccessCode : reportErrorCode);
		}
	};
	_script.onerror = function() {
		complete(reportErrorCode);
	};
	if (timeout) {
		_timer = setTimeout(function() {
			complete(reportTimeoutCode);
		}, parseInt(timeout, 10));
	}
	/*
	setTimeout(function() {
		_script.src = url;
		try {
			_head.insertBefore(_script, _head.lastChild);
		} catch (e) {}
	}, 0);
	
	*/
};

function $loadUrl(o) {
	o.element = o.element || 'script';
	var el = document.createElement(o.element);
	el.charset = o.charset || 'utf-8';
	o.onBeforeSend && o.onBeforeSend(el);
	el.onload = el.onreadystatechange = function() {
		if (/loaded|complete/i.test(this.readyState) || navigator.userAgent.toLowerCase().indexOf("msie") == -1) {
			o.onLoad && o.onLoad();
			clear();
		}
	};
	el.onerror = function() {
		clear();
	};
	el.src = o.url;
	document.getElementsByTagName('head')[0].appendChild(el);

	function clear() {
		if (!el) {
			return;
		}
		el.onload = el.onreadystatechange = el.onerror = null;
		el.parentNode && (el.parentNode.removeChild(el));
		el = null;
	}
};

function $namespace(name) {
	for (var arr = name.split(','), r = 0, len = arr.length; r < len; r++) {
		for (var i = 0, k, name = arr[r].split('.'), parent = {}; k = name[i]; i++) {
			i === 0 ? eval('(typeof ' + k + ')==="undefined"?(' + k + '={}):"";parent=' + k) : (parent = parent[k] = parent[k] || {});
		}
	}
};

function $report(url) {
	$loadUrl({
		'url': url + ((url.indexOf('?') == -1) ? '?' : '&') + Math.random(),
		'element': 'img'
	});
};

function $returnCode(opt) {
	var option = {
		url: "",
		action: "",
		sTime: "",
		eTime: "",
		retCode: "",
		errCode: "",
		frequence: 1,
		refer: "",
		uin: "",
		domain: "paipai.com",
		from: 1,
		report: report,
		isReport: false,
		timeout: 3000,
		timeoutCode: 444,
		formatUrl: true,
		reg: reg
	};
	try {
		option['refer'] = location.href;
	} catch (e) {}
	for (var i in opt) {
		option[i] = opt[i];
	}
	if (option.url) {
		option.sTime = new Date();
	}
	if (option.timeout) {
		setTimeout(function() {
			if (!option.isReport) {
				option.report(false, option.timeoutCode);
			}
		}, option.timeout);
	}

	function reg() {
		this.sTime = new Date();
		if (!this.action) {
			return;
		}
		var rcookie = $getCookie("retcode"),
			cookie2 = [];
		rcookie = rcookie ? rcookie.split("|") : [];
		for (var i = 0; i < rcookie.length; i++) {
			if (rcookie[i].split(",")[0] != this.action) {
				cookie2.push(rcookie[i]);
			}
		}
		cookie2.push(this.action + "," + this.sTime.getTime());
		$setCookie("retcode", cookie2.join("|"), 60, "/", this.domain);
	}

	function report(ret, errid) {
		if (this.isReport == true) {
			return;
		}
		this.isReport = true;
		this.eTime = new Date();
		this.retCode = ret ? 1 : 2;
		this.errCode = isNaN(parseInt(errid)) ? "0" : parseInt(errid);
		if (this.action) {
			this.url = "http://retcode.paipai.com/" + this.action;
			var rcookie = $getCookie("retcode"),
				ret = "",
				ncookie = [];
			rcookie = rcookie ? rcookie.split("|") : [];
			for (var i = 0; i < rcookie.length; i++) {
				if (rcookie[i].split(",")[0] == this.action) {
					ret = rcookie[i].split(",");
				} else {
					ncookie.push(rcookie[i]);
				}
			}
			$setCookie("retcode", ncookie.join("|"), 60, "/", this.domain);
			if (!ret) {
				return;
			}
			this.sTime = new Date(parseInt(ret[1]));
		}
		if (!this.url) {
			return;
		}
		var domain = this.url.replace(/^.*\/\//, '').replace(/\/.*/, ''),
			timer = this.eTime - this.sTime,
			cgi = encodeURIComponent(this.formatUrl ? this.url.match(/^[\w|/|.|:|-]*/)[0] : this.url);
		this.reportUrl = "http://c.isdspeed.qq.com/code.cgi?domain=" + domain + "&cgi=" + cgi + "&type=" + this.retCode + "&code=" + this.errCode + "&time=" + timer + "&rate=" + this.frequence + (this.uin ? ("&uin=" + this.uin) : "");
		if (this.reportUrl && Math.random() < (1 / this.frequence) && this.url) {
			$report(this.reportUrl);
		}
	}
	return option;
};

function $setCookie(name, value, expires, path, domain, secure) {
	var exp = new Date(),
		expires = arguments[2] || null,
		path = arguments[3] || "/",
		domain = arguments[4] || null,
		secure = arguments[5] || false;
	expires ? exp.setMinutes(exp.getMinutes() + parseInt(expires)) : "";
	document.cookie = name + '=' + escape(value) + (expires ? ';expires=' + exp.toGMTString() : '') + (path ? ';path=' + path : '') + (domain ? ';domain=' + domain : '') + (secure ? ';secure' : '');
};

function $time33(str) {
	for (var i = 0, len = str.length, hash = 5381; i < len; ++i) {
		hash += (hash << 5) + str.charAt(i).charCodeAt();
	};
	return hash & 0x7fffffff;
};
$namespace('PP.mobile.ping');
PP.mobile.ping = {
	req_url: window.document.URL,
	req_refer: window.document.referrer ? window.document.referrer : '',
	req_host: window.location.hostname.toLowerCase(),
	sc: '',
	old_pageid: 0,
	old_domainid: 0,
	old_linkid: 0,
	new_pageid: 0,
	new_domainid: 0,
	new_linkid: 0,
	se_pageid: 0,
	se_domainid: 0,
	se_linkid: 0,
	handle_old_rd: function() {
		try {
			var oldrd_reg = /[AR]DTAG=(\d+)\.(\d+)\.(\d+)\D?/gim;
			var arr = oldrd_reg.exec(this.req_url);
			if (arr == null || arr.length != 4) {
				return;
			}
			this.old_pageid = parseInt(arr[1]);
			this.old_domainid = parseInt(arr[2]);
			this.old_linkid = parseInt(arr[3]);
			if (this.old_pageid <= 0 || this.old_domainid <= 0 || this.old_linkid <= 0) {
				return;
			}
			switch (this.old_pageid) {
			case 201:
				this.old_pageid = 601;
				break;
			case 202:
				this.old_pageid = 602;
				break;
			case 701:
				this.old_pageid = 380;
				break;
			default:
				break;
			}
		} catch (e) {}
	},
	handle_new_rd: function() {
		try {
			var newrd_reg = /PTAG[=,](\d+)\.(\d+)\.(\d+)\D?/gim;
			var arr = newrd_reg.exec(this.req_url);
			if (arr == null || arr.length != 4) {
				return;
			}
			this.new_pageid = parseInt(arr[1]);
			this.new_domainid = parseInt(arr[2]);
			this.new_linkid = parseInt(arr[3]);
			if (this.new_pageid <= 0 || this.new_domainid <= 0 || this.new_linkid <= 0) {
				return;
			}
			switch (this.new_pageid) {
			case 201:
				this.new_pageid = 30018;
				break;
			case 202:
				this.new_pageid = 30019;
				break;
			case 603:
				this.new_pageid = 30020;
				break;
			case 701:
				this.new_pageid = 30025;
				break;
			default:
				break;
			}
		} catch (e) {}
	},
	handle_se_refer: function() {
		try {
			if (this.req_refer == null || this.req_refer == '') {
				return;
			}
			var reg = /\.?(\w+)\.(com|cn)/gim;
			var arr = reg.exec(this.req_refer);
			if (arr == null || arr.length < 2) {
				return;
			}
			var se_domain = arr[1].toLowerCase();
			var se_map = {
				baidu: 1,
				google: 2,
				soso: 3,
				3721: 4,
				sogou: 5,
				msn: 6,
				yisou: 7,
				yahoo: 8,
				live: 9,
				yodao: 10,
				iask: 11,
				zhongsou: 12,
				qikoo: 13,
				aol: 14,
				naver: 15,
				yandex: 16,
				ask: 17,
				vnet: 18
			};
			if (se_map[se_domain] != null && !(this.new_pageid >= 40001 && this.new_pageid <= 50000)) {
				this.se_pageid = 40007;
				this.se_domainid = 1;
				this.se_linkid = se_map[se_domain];
			}
		} catch (e) {}
	},
	set_pprd_p_cookie: function(prefix, val) {
		try {
			var rd = prefix + '.' + val,
				expires = new Date((new Date()).getTime() + 259200000),
				cookieName = 'PPRD_P',
				cookieDomain, domainReg = /^(\w+\.|)(wanggou\.com|buy\.qq\.com)$/i,
				pprd_p = $getCookie(cookieName);
			if (!domainReg.test(this.req_host)) {
				return;
			}
			if (pprd_p == null) {
				pprd_p = '';
			}
			var regs = {
				QZZTC: /QZZTC\.([\w\!]+)([^\w\!]?)/gim,
				QZGDT: /QZGDT\.([\w\!]+)([^\w\!]?)/gim,
				CTZTC: /CTZTC\.([^&#]*)(&|$|#)/gim,
				MART: /MART\.([^&#]*)(&|$|#)/gim,
				CPS: /CPS\.([^&#]*)(&|$|#)/gi,
				FOCUS: /FOCUS\.([^&#]*)(&|$|#)/gi,
				CPC: /CPC\.([^&#]*)(&|$|#)/gim,
				QT: /QT\.([\w\!\_\$\|]+)(\W?)/gim
			};
			var reg = regs[prefix];
			if (!reg.test(pprd_p)) {
				pprd_p += (pprd_p.length == 0 ? rd : '-' + rd);
			} else {
				pprd_p = pprd_p.replace(reg, rd + '$2');
			}
			this.sc += (this.sc == '' ? '' : '^') + escape(cookieName) + ';' + escape(pprd_p) + ';' + (expires ? parseInt(expires.getTime() / 1000) : '') + ';';
			cookieDomain = domainReg.exec(this.req_host)[2];
			$setCookie(cookieName, pprd_p, 4320, '/', cookieDomain, 0);
		} catch (e) {}
	},
	handle_pprd_p_cookie: function(prefix, newrd_reg) {
		try {
			var arr = newrd_reg.exec(this.req_url);
			if (arr != null && arr.length >= 2) {
				this.set_pprd_p_cookie(prefix, arr[1]);
			}
		} catch (e) {}
	},
	handle_qzone_ztc: function() {
		var newrd_reg = /qz_express=([\w\!]+)[^\w\!]?/gim;
		this.handle_pprd_p_cookie('QZZTC', newrd_reg);
	},
	handle_qzone_gdt: function() {
		var newrd_reg = /qz_gdt=([\w\!]+)[^\w\!]?/gim;
		this.handle_pprd_p_cookie('QZGDT', newrd_reg);
	},
	handle_paipai_ct: function() {
		var newrd_reg = /pps=exp\.([^&#]*)(&|$|#)/gim;
		this.handle_pprd_p_cookie('CTZTC', newrd_reg);
	},
	handle_paipai_mart: function() {
		var newrd_reg = /pps=mart\.([^&#]*)(&|$|#)/gim;
		this.handle_pprd_p_cookie('MART', newrd_reg);
	},
	handle_paipai_cpc: function() {
		var newrd_reg = /pps=cpc\.([^&#]*)(&|$|#)/gim;
		this.handle_pprd_p_cookie('CPC', newrd_reg);
	},
	handle_paipai_cps: function() {
		var newrd_reg = /pps=cps\.([^&#]*)(&|$|#)/gi;
		this.handle_pprd_p_cookie('CPS', newrd_reg);
	},
	handle_paipai_focus: function() {
		var newrd_reg = /pps=focus\.([^&#]*)(&|$|#)/gi;
		this.handle_pprd_p_cookie('FOCUS', newrd_reg);
	},
	handle_qqtuan_flag: function() {
		var newrd_reg = /tuantg=([\w\!\_\$\|]+)\W?/gim;
		this.handle_pprd_p_cookie('QT', newrd_reg);
	},
	handle_ping_report: function() {
		try {
			var euin = $getUin();
			var url_data = 'r=' + (encodeURIComponent(this.req_refer).substring(0, 512)) + '&u=http://' + this.req_host + '&fu=' + encodeURIComponent(this.req_url) + '&resolution=' + window.screen.width + '*' + window.screen.height + '&color=' + window.screen.colorDepth + '&cookiesup=' + ((typeof(navigator.cookieEnabled) != 'undefined' && navigator.cookieEnabled) ? '1' : '0') + '&pageId=' + this.old_pageid + '&domainId=' + this.old_domainid + '&linkId=' + this.old_linkid + '&fpageId=' + this.new_pageid + '&fdomainId=' + this.new_domainid + '&flinkId=' + this.new_linkid + '&sepageid=' + this.se_pageid + '&sedomainid=' + this.se_domainid + '&selinkid=' + this.se_linkid + '&euin=' + (euin != null ? euin : '') + '&sc=' + this.sc;
			if (typeof(pageMess) == 'object') {
				url_data += '&aa=' + pageMess.commodityClassId + ',' + pageMess.userCredit + ',' + pageMess.userAuth + ',' + pageMess.userProprety + ',' + pageMess.userProprety1 + ',' + pageMess.userProprety2 + ',' + parseInt(parseFloat(pageMess.commodityPrice) * 100 + '') + ',' + pageMess.commodityState;
			}
			if (typeof(shopData) == 'object') {
				url_data += '&aa=' + shopData.userCredit + ',' + shopData.userAuth + ',' + shopData.userProprety1 + ',' + shopData.userProprety2 + ',' + shopData.userProprety3 + ',' + (typeof(shopData.shopType) == 'string' ? shopData.shopType : '');
			}
			var url = 'http://service.paipai.com/cgi-bin/ping?rand=' + Math.round(Math.random() * 100000) + '&' + url_data;
			$loadScript(url);
			window.getPingDataCallBack = function(pingData) {
				console.log(url);
			}
		} catch (e) {}
	},
	main: function() {
		this.handle_old_rd();
		this.handle_new_rd();
		this.handle_se_refer();
		this.handle_qzone_ztc();
		this.handle_qzone_gdt();
		this.handle_paipai_ct();
		this.handle_paipai_mart();
		this.handle_paipai_cpc();
		this.handle_paipai_cps();
		this.handle_paipai_focus();
		this.handle_qqtuan_flag();
		this.handle_ping_report();
	}
}
PP.mobile.ping.main();
window['PP.mobile.ping'] = '21922:20140103:20140106154115';
window['PP.mobile.ping.time'] && window['PP.mobile.ping.time'].push(new Date()); /*  |xGv00|7a370613b5e7f80cacd680bab6907e4f */